#include "ThreadPool.hpp"
#include "task.hpp"
#include <ctime>

int main()
{
    prctl(PR_SET_NAME,"master");

    const string operators = "+-*/%";
    // unique_ptr<ThreadPool<Task>> tp(new ThreadPool<Task>()); // 非单例模式测试
    unique_ptr<ThreadPool<Task> > tp(ThreadPool<Task>::getInstance()); // 单例模式测试
    tp->start();

    srand((unsigned long)time(nullptr) ^ getpid() ^ pthread_self());
    // 派发任务的线程
    while (true)
    {
        int one = rand() % 50;
        int two = rand() % 10;
        char oper = operators[rand() % operators.size()];
        Log() << "派发计算任务：" << one << oper << two << "=?" << endl;
        Task t(one, two, oper);
        tp->push(t);
        sleep(1);
    }
    return 0;
}